﻿/*
   Author: Tomer Paz
   games.com
   2009
*/

/* Play Dialog
	This dialog will ask player to choose between throwing dies or do protperty actions
*/



package monopoly.GameController.Dialogs {
	
	import fl.controls.*;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.EventDispatcher;
	import monopoly.GameController.Dialogs.IDialog;
	import monopoly.GameController.Dialogs.Templates.*;
	import monopoly.Localization.*;
	
	public class PlayDialog extends Sprite implements IDialog
		{
		public static const TYPE_FIRST_MOVE		= 0;
		public static const TYPE_MOVE			= 1;
			
		public static const ACTION_MOVE			= 0;
		public static const ACTION_PROPERTIES	= 1;
		
		protected var _chosen_action:uint;
		protected var _myStrings:ILocalLanguage = LocalLanguage.getInstance();
		
		public function PlayDialog(turnType:uint, isMine:Boolean)
			{
			var rbuttons:Array = new Array();
			rbuttons.push(_myStrings.DlgPlayDiesOption);			

			if (TYPE_FIRST_MOVE == turnType)
				{
				// nothing at this point
				}
			else if (TYPE_MOVE == turnType && isMine)
				{
				rbuttons.push(_myStrings.DlgPlayActionOption);
				}
				
			var dialog = new RadiosDialog(_myStrings.DlgPlayLabel, _myStrings.DlgPlayText, rbuttons);
			dialog.addEventListener(MouseEvent.CLICK, onCmdDialogButtonClick);
			addChild(dialog);
			}
		protected function onCmdDialogButtonClick(e:MouseEvent):void
			{
			if (e.target is Button)
				{
				var dlg:RadiosDialog = e.currentTarget as RadiosDialog;
				_chosen_action = e.currentTarget.ChosenOption;
				
				/* check client has chosen something */
				
				if (BasicDialog.NO_CHOICE == dlg.ChosenOption)
					return;

			
				/* this command is done hence shutdown the dialog */
			
				e.currentTarget.removeEventListener(MouseEvent.CLICK, onCmdDialogButtonClick);
				e.currentTarget.remove( );
				removeChild(Sprite(e.currentTarget));
				
				/* signal game controller we are done */
				
				dispatchEvent(new Event(Event.COMPLETE));
				}
			}
			
		public function get chosenAction():uint
					{
					return this._chosen_action;
					}
		}
}